<?php

App::uses('AppController', 'Controller');

class BrandsController extends AppController {

    private function __brands($slug = null) {
        $brand_options = array(
            'recursive' => -1,
            'conditions' => array(
                'Brand.active' => 1
            ),
            'order' => array(
                'Brand.name' => 'ASC'
            )
        );
        $brands = $this->Brand->find('all', $brand_options);
        $settings = array(
            'Product' => array(
                'limit' => 12,
                'recursive' => -1,
                'contain' => array(
                    'Brand'
                ),
                'conditions' => array(
                    'Product.active' => 1,
                    'Brand.active' => 1,
                ),
                'order' => array(
                    'Product.name' => 'ASC'
                )
            )
        );
        if ($slug != NULL) {
            $brand_options['conditions']['Brand.slug'] = $slug;
            $brand = $this->Brand->find('first', $brand_options);
            $settings['Product']['conditions']['Product.brand_id'] = $brand['Brand']['id'];
            $this->set(compact('brand'));
        }
        $this->Paginator->settings = $settings;
        $products = $this->Paginator->paginate($this->Brand->Product);

        $this->set(compact('products'));
        $this->set(compact('brands'));
    }

    public function index() {
        $this->__brands();
    }

    public function view($slug = null) {
        $this->__brands($slug);
    }

    /* -------------------------------- Administração ----------------------------------------------------- */

    /**
     * Lista todos os "usuarios".
     *
     * @method        admin_index
     * @version       1.0.0
     * @return void
     */
    public function admin_index() {
        parent::admin_index();
    }

    /**
     * Cadastrar "usuarios"
     *
     * @method        admin_add
     * @version       1.0.0
     * @return void
     */
    public function admin_add() {
        parent::admin_add();
    }

    /**
     * Alterar de acordo com o ID  "usuarios" especifico.
     *
     * @method        admin_edit
     * @version       1.0.0
     * @throws NotFoundException
     * @param string $id
     * @return void
     */
    public function admin_edit($id = null) {
        parent::admin_edit($id);
    }

    /**
     * Excluir de acordo com o ID  "usuarios" especifico.
     *
     * @method        admin_delete
     * @version       1.0.0
     * @throws NotFoundException
     * @param string $id
     * @return void
     */
    public function admin_delete($id = null) {
        parent::admin_delete($id);
    }

    /**
     * Exportar dados do banco em formato CSV da tabela "usuarios".
     *
     * @method        admin_export_data
     * @version       1.0.0
     * @return void
     */
    public function admin_export() {
        parent::admin_export();
    }

    /**
     * Detalhes do registro.
     *
     * @method        admin_view
     * @version       1.0.0
     * @return void
     */
    public function admin_view($id = null) {
        parent::admin_view($id);
    }

}
